import React, { Component } from "react";
import { connect } from "react-redux";
import "./PayRet.scss";
import XFButton from "../../../../xfCompontent/xfButton/xfButton";
import openFail from "../../../../images/imageXHF/openFail.png";
import successUrl from "../../../../images/imageXHF/paying.png";
import MainLayout from "../../../../component/mainLayout/mainLayout";

class PayRet extends Component {
	constructor(props) {
		super(props);
		this.state = {
			btnText: "返回首页",
			respCode: "",
			retText: "",
			message: "",
			imgUrl: "",
			tipText: ""
		};
	}

	componentDidMount() {
		const urlParams = this.props.location.state;
		const respCode = urlParams.respCode;
		if (respCode == "1111" || respCode == "0000") {
			this.setState({
				retText: "还款中",
				imgUrl: successUrl,
				tipText: "请稍后查看还款结果"
			});
		} else {
			this.setState({
				retText: "还款失败",
				imgUrl: openFail,
				tipText: ""
			});
		}
	}

	btnFn() {
		if (this.props.getAppPlatformsDatas.lnid === "802") {
			location.replace("#/xhdHome");
		} else {
			location.replace("#/xhfHomeCredit");
		}
	}

	render() {
		const headerParams = {
			header: {
				title: "还款结果",
				goBackPath:
					this.props.getAppPlatformsDatas.lnid == "802"
						? "xhdHome"
						: "XhfHomeCredit"
			},
			history: this.props.history,
			cacheLifecycles: this.props.cacheLifecycles,
			loadStatus: "1" // （ '0'：数据加载中，'1'：加载完成，'2'：加载失败）
		};
		const btnStyle = {
			height: "0.80rem",
			width: "6.96rem",
			borderRadius: ".40rem"
		};

		const { tipText, btnText } = this.state;
		return (
			<MainLayout pageParams={headerParams}>
				<div className="openFail">
					<div className="openFail-box">
						<img src={this.state.imgUrl} />
						<h3>{this.state.retText}</h3>
						<p>{tipText}</p>
					</div>
					<XFButton
						handleBtn={this.btnFn.bind(this)}
						btText={btnText}
						btnStyle={btnStyle}
					/>
				</div>
			</MainLayout>
		);
	}
}

function mapStateToProps(state) {
	return state;
}

function mapDispatchToProps() {
	return {};
}

const PayRetPage = connect(mapStateToProps, mapDispatchToProps)(PayRet);
export default PayRetPage;
